package com.ktjy.springredis;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

public class JedisTester {
    private Jedis jedis;

    @BeforeEach
    public void setup(){
        //连接redis 服务器 127.0.0.1:6379
        jedis=new Jedis("127.0.0.1",6379);
    }

    @Test
    public void testString(){
        //添加数据
        jedis.set("name","ktjy");//向key-->name中放入了value-->ktjy
        System.out.println(jedis.get("name")); //执行结果

        jedis.append("name","czkt"); //拼接
        System.out.println(jedis.get("name"));

        jedis.del("name"); //删除某个key,返回结果1
        System.out.println(jedis.get("name"));

        //设置多个键值对
        jedis.mset("name","ktjy","age","18","qq","123456");
        jedis.incr("age"); //age自增1
        //输出所有
        System.out.println(jedis.mget("name","age","qq"));
        //删除多个键值对
        System.out.println(jedis.del("name","age","qq"));
    }
}
